package cn.java.web.side.validate.config;

import org.springframework.http.HttpStatus;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;

/**
 * 全局异常
 */
@ControllerAdvice
public class GlobalExceptionHandler {


    /**
     * 处理普通异常
     */
    @ExceptionHandler(value = { MethodArgumentNotValidException.class })
    @ResponseStatus(code = HttpStatus.INTERNAL_SERVER_ERROR)
    @ResponseBody
    public void handleCommonException(MethodArgumentNotValidException ex) {

        System.out.println(ex.getBindingResult().getAllErrors().get(0).getDefaultMessage());
    }


}
